package cn.tedu.simulateioc3;/**
 * @Author 金帮嘉诚 @Date 2021-07-16 星期五 20:18
 */
/*本类用于测试*/

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**知识点*/
public class MyIoC3 {
    private List<Bean3> bean3Factory = new ArrayList<>();
    private final Map<String,Object> factoryBean3Object=new ConcurrentHashMap<>();

    public MyIoC3() throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        Bean3 bean31=new Bean3("hello3","cn.tedu.simulateioc3.Hello3");
        Bean3 bean32=new Bean3("user3","cn.tedu.simulateioc3.User3");
        Bean3 bean33=new Bean3("sun3","cn.tedu.simulateioc3.Sun3");
        bean3Factory.add(bean31);
        bean3Factory.add(bean32);
        bean3Factory.add(bean33);
        init();
    }
    private void init() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        for (Bean3 b:bean3Factory
             ) {
            String key=b.getBeanName();
            String path=b.getBeanPath();
            Object value=Class.forName(path).newInstance();
            factoryBean3Object.put(key,value);
        }
    }
    public Object getBean3(String beanName){
        return factoryBean3Object.get(beanName);
    }

}
